package com.mangofactory.aop.configuration
{
	import com.mangofactory.aop.SimpleCalculator;
	import com.mangofactory.aop.StubAspect;
	import com.mangofactory.aop.aspects.LoggingAspect;
	import com.mangofactory.aop.configuration.tag.MetatagAspectDefinition;
	
	import flash.events.Event;
	
	import org.flexunit.asserts.assertTrue;
	import org.flexunit.async.Async;
	import org.flexunit.async.AsyncHandler;

	public class ApsectContainerBuilderTests
	{
		[Test(async)]
		public function testBuilder():void
		{
			var aspect:StubAspect = new StubAspect();
			var aspectContainer:AspectContainer = new AspectContainerBuilder()
				.addClass(SimpleCalculator)
				.addMetatagAspect(new MetatagAspectDefinition("Log",aspect))
				.build();
			var handler:Function = Async.asyncHandler(this,onAspectBuilt,2000,[aspectContainer,aspect])
			aspectContainer.addEventListener(Event.COMPLETE,handler);
		}
		private function onAspectBuilt(event:Event,params:Array):void
		{
			var container:AspectContainer = params[0] as AspectContainer;
			var aspect:StubAspect = params[1] as StubAspect;
			
			var calculator:SimpleCalculator = container.newInstance(SimpleCalculator);
			calculator.add(2,3);
			assertTrue(calculator.wasCalled);
			assertTrue(aspect.wasCalled);
		}
	}
}